package StructuralPattern.FlyweightPattern;

import StructuralPattern.FlyweightPattern.Interfase.ChessPiece;

public class TestFlyweightPattern {
    public static void main(String[] args) {
        ChessPieceFactory factory = new ChessPieceFactory();

        // 创建并共享白色棋子
        ChessPiece white1 = factory.getChessPiece("White");
        white1.place(1, 1);

        ChessPiece white2 = factory.getChessPiece("White");
        white2.place(2, 2);

        // 创建并共享黑色棋子
        ChessPiece black1 = factory.getChessPiece("Black");
        black1.place(3, 3);

        ChessPiece black2 = factory.getChessPiece("Black");
        black2.place(4, 4);

        // 验证共享的对象
        System.out.println(white1 == white2); // true，表明共享了白色棋子对象
        System.out.println(black1 == black2); // true，表明共享了黑色棋子对象
    }
}
